<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax的post请求</title>
    <style>
        div {
            width: 300px;
            height: 200px;
            border: 1px solid #000;

        }
    </style>
</head>

<body>
    <div id="result"></div>
    <script>
        var result = document.querySelector('#result');
        result.addEventListener('mouseover', function () {
            // console.log(result);
            //创建对象
            var xhr = new XMLHttpRequest();
            //初始化，设置参数与类型
            xhr.open('POST', 'http://127.0.0.1:8000/server');
            //发送
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            xhr.send('a=100');
            //事件绑定
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status == 200) {
                        result.innerHTML = xhr.response;
                    }

                }
            }
        })
    </script>
</body>

</html>